package collect.taobao.action;

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.apache.log4j.Logger;
import javax.imageio.ImageIO;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import collect.taobao.bean.MailBean;
import collect.taobao.util.SuperAction;
import collect.taobao.util.groupPage.PageBuffer;
import collect.taobao.util.groupPage.Pagination;

public class ImageExplorer extends SuperAction {
	public List pageList = new ArrayList();
	private static Logger logger = Logger.getLogger(ImageExplorer.class
			.getName());
	public String gallery() throws IOException {

		HttpServletRequest request = this.getReq();
		HttpServletResponse response = this.getResp();

		// String path = request.getParameter("path");
		String path = "D:/manhua/sishen/diyi/zzz.jpg";
		response.addHeader("Content-Type", "image/jpeg");
		response.setHeader("Pragma", "No-cache");
		response.setHeader("Cache-Control", "no-cache");
		response.setDateHeader("Expires", 0);
		try {
			BufferedImage img = null;
			img = ImageIO.read(new File(path));
			ImageIO.write(img, "jpeg", response.getOutputStream());

		} catch (Exception e) {
		} finally {
		}
		return "success";
	}

	
	public String groupPage() {
		
		try {
			logger.debug("This is debug message.");
			// 记录info级别的信息
			logger.info("This is info message.");
			// 记录error级别的信息
			logger.error("This is error message.");
		} catch (Exception e) {
			logger.info("log出错啦：" + e.getMessage());
		}
		 HttpServletRequest request = this.getReq();
		String pageNo = request.getParameter("PageNo");
		int currentPageNo=0;
		if (pageNo == null || "".equals(pageNo)) {
			currentPageNo = 1;
		}else{
			currentPageNo = Integer.parseInt(pageNo);
		}
		String url = "showImage!groupPage.action";
		String sql  = "select * from emailtable.imagestream  ORDER BY  NAME ASC " ;
		PageBuffer pg  = Pagination.pageContent(currentPageNo, sql, url,3);
		List list  = pg.getList();
		if (list != null && list.size() > 0) {
			for (int i = 0; i < list.size(); i++) {
				MailBean mailbean = new MailBean();
				Object[] obj = (Object[]) list.get(i);
				String emailUrl = (String) obj[2];
				mailbean.setEmailUrl(emailUrl);
				pageList.add(mailbean);
			}

		}
		request.setAttribute("pagination", pg.getNavigator1());
		return "groupPageSuccess";
	}

	public List getPageList() {
		return pageList;
	}

	public void setPageList(List pageList) {
		this.pageList = pageList;
	}

}
